package com.suns.demo;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class SyncProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("suns_sync_producer");
//        producer.setNamespace();
//        producer.setSendMsgTimeout();
        producer.setNamesrvAddr("localhost:9876");
//        producer.setMaxMessageSize();
//        producer.setRetryTimesWhenSendFailed(2);
        producer.start();

        Message message = null;

        for (int i = 0; i < 5; i++) {
            message = new Message("suns_tp_01", ("这是suns同步消息-" + i).getBytes(StandardCharsets.UTF_8));
            SendResult result = producer.send(message);
            System.out.println(result);
        }
        producer.shutdown();
    }
}
